package cn.edu.xhu.library_management.user.service.impl;

import cn.edu.xhu.library_management.user.entity.pojo.LmBook;
import cn.edu.xhu.library_management.user.utils.AccountUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.edu.xhu.library_management.user.entity.LmReservation;
import cn.edu.xhu.library_management.user.service.LmReservationService;
import cn.edu.xhu.library_management.user.mapper.LmReservationMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author 21086
* @description 针对表【lm_reservation(预约表)】的数据库操作Service实现
* @createDate 2023-04-29 09:26:00
*/
@Service
public class LmReservationServiceImpl extends ServiceImpl<LmReservationMapper, LmReservation>
    implements LmReservationService{


    @Override
    public boolean reservationBook(LmReservation reservation) {
        // 查询当前用户是否重复预约
        QueryWrapper<LmReservation> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(LmReservation::getUserAccount,reservation.getUserAccount());
        queryWrapper.lambda().eq(LmReservation::getBoId,reservation.getBoId());
        LmReservation re = this.getOne(queryWrapper);
        System.out.println("====>"+re);
        if (re != null){
            return false;
        }
        // 获取用户类
        reservation.setUserType(AccountUtils.getAccountType(reservation.getUserAccount()));
        reservation.setReDelFlag("1");
        return this.save(reservation);
    }

    @Override
    public List<LmBook> getReservationBook(String userAccount) {
        // 获取当前用户的预约记录
        List<LmReservation> reservations = this.list(new QueryWrapper<LmReservation>().lambda().eq(LmReservation::getUserAccount, userAccount));
        // 使用记录，获取对应的图书信息
        return null;
    }
}




